package pl.edu.pw.polygen.modeler.client.object.listener;

import java.util.HashMap;
import java.util.Map;

public class PolygenObjectListenerMultiton {

	private static PolygenObjectListenerMultiton instance = null;
	private static Map<String, IPolygenObjectListener> listenersMap;

	private PolygenObjectListenerMultiton() {
	}

	private static void initialize() {
		listenersMap = new HashMap<String, IPolygenObjectListener>();
		listenersMap.put(SelectableVertexListener.class.getName(), new SelectableVertexListener());
		listenersMap.put(SelectableSegmentListener.class.getName(), new SelectableSegmentListener());
		listenersMap.put(SelectableSplainListener.class.getName(), new SelectableSplainListener());
		listenersMap.put(SelectableControlListener.class.getName(), new SelectableControlListener());
		listenersMap.put(MergeVertexListener.class.getName(), new MergeVertexListener());
		listenersMap.put(LockedVertexListener.class.getName(), new LockedVertexListener());
		listenersMap.put(EmptyListener.class.getName(), new EmptyListener());
	}

	public static IPolygenObjectListener getInstance(Class clazz) {
		if (instance == null) {
			instance = new PolygenObjectListenerMultiton();
			initialize();
		}
		if (listenersMap.containsKey(clazz.getName())) {
			return listenersMap.get(clazz.getName());
		} else
			return null;
	}

}
